package com.yubest.customserializer.controller;

import com.yubest.customserializer.dto.DemoRespDTO;
import com.yubest.customserializer.dto.Response;
import com.yubest.customserializer.enums.Status2Enum;
import com.yubest.customserializer.enums.StatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author hweiyu
 * @Description
 * @Date 2021/3/1 14:01
 */
@RestController
@Slf4j
public class DemoController {

    /**
     * @return
     */
    @GetMapping(value = "/test")
    public Response<DemoRespDTO> test() {
        DemoRespDTO respDTO = new DemoRespDTO();
        respDTO.setStatus11(StatusEnum.NORMAL);
        respDTO.setStatus12(StatusEnum.DISABLE);
        respDTO.setStatus13(StatusEnum.NORMAL.getType());
        respDTO.setStatus21(Status2Enum.NORMAL);
        respDTO.setStatus22(Status2Enum.NORMAL.getType());
        respDTO.setStatus3(1);
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("1.png");
        try {
            respDTO.setFile(StreamUtils.copyToByteArray(is));
        } catch (IOException e) {
            log.error("test error", e);
        }
        return Response.success(respDTO);
    }

}
